home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / labeldisk / tmp < prev    next >
Encoding:
Text File  |  1992-09-08  |  44.1 KB  |  1,465 lines

  1. *** /tmp/,RCSt1335642    Mon Sep  7 19:41:37 1992
  2. --- labeldisk.c    Mon Sep  7 19:35:19 1992
  3. ***************
  4. *** 8,37 ****
  5.    */
  6.   
  7.   #ifndef lint
  8. ! static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.7 90/02/16 16:11:43 shirriff Exp $ SPRITE (Berkeley)";
  9.   #endif not lint
  10.   
  11. ! #include "sprite.h"
  12.   #include "option.h"
  13. ! #include "sys/file.h"
  14. ! #include "stdio.h"
  15. ! #include "errno.h"
  16. ! #include "diskUtils.h"
  17. ! #include "kernel/dev.h"
  18.   
  19.   /*
  20.    * Constants settable via the command line.
  21.    */
  22. ! char *deviceName;        /* ie. set to "/dev/rsd0" */
  23.   Boolean writeLabel = FALSE;
  24.   Boolean writeSun = FALSE;
  25.   Boolean writeDec = FALSE;
  26. - Boolean writeSprite = FALSE;
  27.   Boolean newLabel = FALSE;
  28.   
  29.   Option optionArray[] = {
  30.       {OPT_DOC,"",(Address)NIL,
  31. !     "labeldisk [-w] [-sun] [-dec] [-sprite] [-new] rawDevice"},
  32.       {OPT_TRUE, "w", (Address)&writeLabel,
  33.       "Write a new disk label"},
  34.       {OPT_TRUE, "sun", (Address)&writeSun,
  35. --- 8,41 ----
  36.    */
  37.   
  38.   #ifndef lint
  39. ! static char rcsid[] = "$Header: /sprite/src/cmds/labeldisk/RCS/labeldisk.c,v 1.15 92/02/06 12:05:21 voelker Exp Locker: voelker $ SPRITE (Berkeley)";
  40.   #endif not lint
  41.   
  42. ! #include <sprite.h>
  43.   #include "option.h"
  44. ! #include "disk.h"
  45. ! #include <sys/file.h>
  46. ! #include <stdio.h>
  47. ! #include <errno.h>
  48. ! #include <kernel/dev.h>
  49.   
  50. + #define Min(a,b) (((a) < (b)) ? (a) : (b))
  51.   /*
  52.    * Constants settable via the command line.
  53.    */
  54. ! char *fromName;         /* e.g. set to "/dev/rsd0" */
  55. ! char *toName;        /* e.g. set to "/dev/rsd0g" */
  56.   Boolean writeLabel = FALSE;
  57.   Boolean writeSun = FALSE;
  58.   Boolean writeDec = FALSE;
  59.   Boolean newLabel = FALSE;
  60. + Boolean writeQuick = FALSE;
  61.   
  62.   Option optionArray[] = {
  63.       {OPT_DOC,"",(Address)NIL,
  64. !     "labeldisk [-from fromDevice] [-w] [-q] [-sun] [-dec] [-new] toDevice"},
  65. !     {OPT_STRING, "from", (char *)&fromName,
  66. !     "Read the disk label from this partition"},
  67.       {OPT_TRUE, "w", (Address)&writeLabel,
  68.       "Write a new disk label"},
  69.       {OPT_TRUE, "sun", (Address)&writeSun,
  70. ***************
  71. *** 38,64 ****
  72.       "Write a Sun label"},
  73.       {OPT_TRUE, "dec", (Address)&writeDec,
  74.       "Write a Dec label"},
  75. -     {OPT_TRUE, "sprite", (Address)&writeSprite,
  76. -     "Write a Sprite label"},
  77.       {OPT_TRUE, "new", (Address)&newLabel,
  78.       "Ignore any old label"},
  79.   };
  80.   int numOptions = sizeof(optionArray) / sizeof(Option);
  81.   
  82. ! extern short SeeSunCheckSum();
  83. ! extern unsigned int SeeSpriteCheckSum();
  84. ! void    ConvertSunToSprite();
  85. ! void    ConvertSpriteToSun();
  86. ! void    ConvertDecToSprite();
  87. ! void    ConvertSpriteToDec();
  88. ! ReturnStatus    EraseOldLabel();
  89. ! #define NOLABEL -1
  90. ! #define SUNLABEL 0
  91. ! #define SPRITELABEL 1
  92. ! #define DECLABEL 2
  93.   
  94.   /*
  95.    *----------------------------------------------------------------------
  96. --- 42,58 ----
  97.       "Write a Sun label"},
  98.       {OPT_TRUE, "dec", (Address)&writeDec,
  99.       "Write a Dec label"},
  100.       {OPT_TRUE, "new", (Address)&newLabel,
  101.       "Ignore any old label"},
  102. +     {OPT_TRUE, "q", (Address)&writeQuick,
  103. +     "Copy label quickly, without prompting to change the label"}
  104.   };
  105.   int numOptions = sizeof(optionArray) / sizeof(Option);
  106.   
  107. ! static ReturnStatus    LabelDisk();
  108. ! static void        EditLabel();
  109. ! static void        InputNumber();
  110. ! static int        IsYes();
  111.   
  112.   /*
  113.    *----------------------------------------------------------------------
  114. ***************
  115. *** 80,94 ****
  116.       char *argv[];
  117.   {
  118.       int openFlags;
  119. !     int streamID;
  120.   
  121.       argc = Opt_Parse(argc, argv, optionArray, numOptions);
  122.       if (argc != 2) {
  123. !     Opt_PrintUsage(argv[0], optionArray, numOptions);
  124. !     exit(FAILURE);
  125. !     }
  126. !     deviceName = argv[1];
  127. !     if (writeSun || writeSprite || writeDec) {
  128.       writeLabel = TRUE;
  129.       }
  130.       if (writeLabel) {
  131. --- 74,98 ----
  132.       char *argv[];
  133.   {
  134.       int openFlags;
  135. !     int toStreamID;
  136. !     int fromStreamID;
  137. !     int tmp;
  138.   
  139.       argc = Opt_Parse(argc, argv, optionArray, numOptions);
  140.       if (argc != 2) {
  141. !     if (argc == 1 && fromName != NULL && strlen(fromName) > 0) {
  142. !         toName = fromName;
  143. !     } else {
  144. !         Opt_PrintUsage(argv[0], optionArray, numOptions);
  145. !         exit(FAILURE);
  146. !     }
  147. !     } else {
  148. !     if (fromName == NULL || strlen(fromName) == 0) {
  149. !         fromName = argv[1];
  150. !     }
  151. !     toName = argv[1];
  152. !     } 
  153. !     if (writeSun || writeDec || writeQuick) {
  154.       writeLabel = TRUE;
  155.       }
  156.       if (writeLabel) {
  157. ***************
  158. *** 96,114 ****
  159.       } else {
  160.       openFlags = O_RDONLY;
  161.       }
  162. !     if ( (writeSun?1:0)+(writeSprite?1:0)+(writeDec?1:0) > 1) {
  163.       fprintf(stderr,
  164. !         "Can't specify more than one of -sun, -dec, -sprite.\n");
  165.       Opt_PrintUsage(argv[0], optionArray, numOptions);
  166.       exit(FAILURE);
  167.       } 
  168. !     streamID = open(deviceName, openFlags, 0);
  169. !     if (streamID < 0) {
  170.       perror("Can't open device");
  171.       exit(FAILURE);
  172.       }
  173. !     if (LabelDisk(streamID) != SUCCESS) {
  174. !     perror("labeldisk");
  175.       }
  176.       exit(errno);
  177.   }
  178. --- 100,133 ----
  179.       } else {
  180.       openFlags = O_RDONLY;
  181.       }
  182. !     if ((writeSun?1:0)+(writeDec?1:0) > 1) {
  183.       fprintf(stderr,
  184. !         "Can't specify more than one of -sun, -dec.\n");
  185.       Opt_PrintUsage(argv[0], optionArray, numOptions);
  186.       exit(FAILURE);
  187.       } 
  188. !     fromStreamID = open(fromName, openFlags, 0);
  189. !     if (fromStreamID < 0) {
  190.       perror("Can't open device");
  191.       exit(FAILURE);
  192.       }
  193. !     tmp = strcmp(fromName, toName);
  194. !     if (tmp) {
  195. !     toStreamID = open(toName, openFlags, 0);
  196. !     if (toStreamID < 0) {
  197. !         perror("Can't open device");
  198. !         exit(FAILURE);
  199. !     }
  200. !     } else {
  201. !     toStreamID = fromStreamID;
  202. !     }
  203. !     if (LabelDisk(fromStreamID, toStreamID) != SUCCESS) {
  204. !     if (errno == 0) {
  205. !         fprintf(stderr, "labeldisk: Short read, or EOF encountered ");
  206. !         fprintf(stderr, "on most likely an empty partition.\n");
  207. !     } else {
  208. !         perror("labeldisk");
  209. !     }
  210.       }
  211.       exit(errno);
  212.   }
  213. ***************
  214. *** 127,220 ****
  215.    *
  216.    *----------------------------------------------------------------------
  217.    */
  218. ! ReturnStatus
  219. ! LabelDisk(streamID)
  220. !     int streamID;            /* Handle on raw disk */
  221.   {
  222. !     Disk_Info             *diskInfoPtr;
  223. !     Sun_DiskLabel         *sunLabelPtr;
  224. !     Dec_DiskLabel         *decLabelPtr;
  225. !     Fsdm_DiskHeader        *diskHeaderPtr;
  226. !     Disk_Info            diskInfo;
  227. !     Sun_DiskLabel        sunLabel;
  228. !     Dec_DiskLabel        decLabel;
  229. !     Fsdm_DiskHeader        diskHeader;
  230.       int             n;
  231.       char             answer[80];
  232. !     int             inLabel, outLabel;
  233. !     static char    *labelName[3] = {"Sun", "Sprite", "Dec"};
  234. !     static char buffer[1024], buffer2[1024];
  235.       ReturnStatus        status;
  236.   
  237.       if (writeSun) {
  238. !     outLabel = SUNLABEL;
  239.       } else if (writeDec) {
  240. !     outLabel = DECLABEL;
  241. !     } else if (writeSprite) {
  242. !     outLabel = SPRITELABEL;
  243. !     } else {
  244. !     outLabel = -1;
  245. !     }
  246. !     diskHeaderPtr = (Fsdm_DiskHeader *)buffer;
  247. !     decLabelPtr = (Dec_DiskLabel *)buffer2;
  248. !     diskInfoPtr = Disk_ReadDiskInfo(streamID, 0);
  249. !     if (!newLabel && diskInfoPtr != (Disk_Info *)0) {
  250. !     sunLabelPtr = Disk_ReadSunLabel(streamID);
  251. !     if (sunLabelPtr != (Sun_DiskLabel *)0) {
  252. !         inLabel = SUNLABEL;
  253. !     } else {
  254. !         sunLabelPtr = (Sun_DiskLabel *)buffer2;
  255. !         diskHeaderPtr = Disk_ReadDiskHeader(streamID);
  256. !         if (diskHeaderPtr != (Fsdm_DiskHeader *) 0) {
  257. !         inLabel = SPRITELABEL;
  258. !         } else {
  259. !         diskHeaderPtr = (Fsdm_DiskHeader *)buffer;
  260. !         decLabelPtr = Disk_ReadDecLabel(streamID);
  261. !         if (decLabelPtr != (Dec_DiskLabel *)0) {
  262. !             inLabel = DECLABEL;
  263. !         } else {
  264. !             fprintf(stderr, "Disk label is neither Sun nor Sprite.\n");
  265. !             return(FAILURE);
  266. !         }
  267. !         }
  268. !     }
  269.       } else {
  270. !     inLabel = NOLABEL;
  271.       if (!newLabel) {
  272.           printf("The disk does not have a label.\n");
  273.       }
  274.       if (!writeLabel) {
  275. !         return(FAILURE);
  276.       }
  277. !     if (outLabel == NOLABEL) {
  278. !         printf("You must specify the -sun, -dec, or -sprite option.\n");
  279. !         return(FAILURE);
  280. !     }
  281. !     bzero(&diskInfo, sizeof(Disk_Info));
  282. !     bzero(&sunLabel, sizeof(Sun_DiskLabel));
  283. !     bzero(&decLabel, sizeof(Dec_DiskLabel));
  284. !     bzero(&diskHeader, sizeof(Fsdm_DiskHeader)); diskInfoPtr = &diskInfo;
  285. !     if (outLabel == DECLABEL) {
  286. !         diskInfoPtr->bootSector = DEC_BOOT_SECTOR;
  287. !         diskInfoPtr->numBootSectors = DEC_LABEL_SECTOR-1;
  288. !         diskInfoPtr->summarySector = DEC_SUMMARY_SECTOR;
  289. !         diskInfoPtr->domainSector = DEC_DOMAIN_SECTOR;
  290. !     } else {
  291. !         diskInfoPtr->bootSector = 1;
  292. !         diskInfoPtr->numBootSectors = 15;
  293. !         diskInfoPtr->summarySector = 17;
  294. !         diskInfoPtr->domainSector = 18;
  295. !     }
  296. !     diskInfoPtr->numDomainSectors = FSDM_NUM_DOMAIN_SECTORS;
  297. !     sunLabelPtr = &sunLabel;
  298. !     decLabelPtr = &decLabel;
  299. !     diskHeaderPtr = &diskHeader;
  300.       }
  301. !     if (outLabel == NOLABEL) {
  302.       outLabel = inLabel;
  303.       }
  304. !     if ((inLabel != outLabel) && (inLabel != NOLABEL)) {
  305.       /*
  306.        * At this point, the output label should be an empty buffer.
  307.        * diskHeaderPointer should be a valid label or empty buffer.
  308. --- 146,197 ----
  309.    *
  310.    *----------------------------------------------------------------------
  311.    */
  312. ! static ReturnStatus
  313. ! LabelDisk(fromStreamID, toStreamID)
  314. !     int fromStreamID;            /* Handle on raw input disk */
  315. !     int toStreamID;                     /* Handle on raw output disk */
  316.   {
  317. !     Disk_Label             *diskLabelPtr;
  318.       int             n;
  319.       char             answer[80];
  320. !     Disk_NativeLabelType    inLabel, outLabel;
  321. !     static char                 buffer[1024], buffer2[1024];
  322.       ReturnStatus        status;
  323. !     Ofs_DomainHeader            *headerPtr;
  324.   
  325.       if (writeSun) {
  326. !     outLabel = DISK_SUN_LABEL;
  327.       } else if (writeDec) {
  328. !     outLabel = DISK_DEC_LABEL;
  329.       } else {
  330. !     outLabel = DISK_NO_LABEL;
  331. !     }
  332. !     diskLabelPtr = Disk_ReadLabel(fromStreamID);
  333. !     if (newLabel || diskLabelPtr == NULL) {
  334.       if (!newLabel) {
  335.           printf("The disk does not have a label.\n");
  336.       }
  337.       if (!writeLabel) {
  338. !         return FAILURE;
  339.       }
  340. !     if (outLabel == DISK_NO_LABEL) {
  341. !         printf("You must specify the -sun, or -dec option.\n");
  342. !         return FAILURE;
  343. !     }
  344. !     inLabel = DISK_NO_LABEL;
  345. !     diskLabelPtr = Disk_NewLabel(outLabel);
  346.       }
  347. !     if (diskLabelPtr != NULL) {
  348. !     inLabel = diskLabelPtr->labelType;
  349. !     }
  350. !     if (outLabel == DISK_NO_LABEL) {
  351.       outLabel = inLabel;
  352.       }
  353. !     Disk_PrintLabel(diskLabelPtr);
  354. !     if (!writeLabel) {
  355. !     return SUCCESS;
  356. !     }
  357. !     if (inLabel != outLabel) {
  358.       /*
  359.        * At this point, the output label should be an empty buffer.
  360.        * diskHeaderPointer should be a valid label or empty buffer.
  361. ***************
  362. *** 222,228 ****
  363.        */
  364.       printf(
  365.         "Do you really want to replace a %s label with a %s label? (y/n) ",
  366. !       labelName[inLabel], labelName[outLabel]);
  367.       n = scanf("%s", answer);
  368.       if (n == EOF) {
  369.           exit(1);
  370. --- 199,205 ----
  371.        */
  372.       printf(
  373.         "Do you really want to replace a %s label with a %s label? (y/n) ",
  374. !       Disk_GetLabelTypeName(inLabel), Disk_GetLabelTypeName(outLabel));
  375.       n = scanf("%s", answer);
  376.       if (n == EOF) {
  377.           exit(1);
  378. ***************
  379. *** 230,613 ****
  380.       if (strcasecmp(answer, "y")) {
  381.           exit(1);
  382.       }
  383. -     /*
  384. -      * Make input into a Sprite label.  Then change to output label.
  385. -      */
  386. -     if (inLabel == SUNLABEL) {
  387. -         ConvertSunToSprite(diskInfoPtr, sunLabelPtr, diskHeaderPtr);
  388. -     } else if (inLabel == DECLABEL) {
  389. -         ConvertDecToSprite(diskInfoPtr, decLabelPtr, diskHeaderPtr);
  390. -     }
  391. -     if (outLabel == SUNLABEL) {
  392. -         ConvertSpriteToSun(diskInfoPtr, diskHeaderPtr, sunLabelPtr);
  393. -     } else if (outLabel == DECLABEL) {
  394. -         ConvertSpriteToDec(diskInfoPtr, diskHeaderPtr, decLabelPtr);
  395. -     }
  396. -     }
  397. -     /*
  398. -      * At this point, the output label should be valid.
  399. -      */
  400. -     if (outLabel == SUNLABEL) {
  401. -     status = DoSunLabel(diskInfoPtr, streamID, sunLabelPtr);
  402. -     } else if (outLabel == DECLABEL) {
  403. -     status = DoDecLabel(diskInfoPtr, streamID, decLabelPtr);
  404. -     } else {
  405. -     status = DoSpriteLabel(diskInfoPtr, streamID, diskHeaderPtr);
  406. -     }
  407. -     if (status == SUCCESS && inLabel != NOLABEL) {
  408. -     int oldsector, newsector;
  409. -     oldsector = inLabel == DECLABEL ? DEC_LABEL_SECTOR : 0;
  410. -     newsector = outLabel == DECLABEL ? DEC_LABEL_SECTOR : 0;
  411. -     if (oldsector != newsector) {
  412. -         status = EraseOldLabel(streamID, oldsector);
  413. -     }
  414.       }
  415. !     return status;
  416. ! }
  417. ! /*
  418. !  *----------------------------------------------------------------------
  419. !  *
  420. !  * DoSunLabel --
  421. !  *
  422. !  *    Sets up a Sun label.
  423. !  *
  424. !  * Results:
  425. !  *    None.
  426. !  *
  427. !  * Side effects:
  428. !  *    None.
  429. !  *
  430. !  *----------------------------------------------------------------------
  431. !  */
  432. ! ReturnStatus
  433. ! DoSunLabel(diskInfoPtr, streamID, sunLabelPtr)
  434. !     Disk_Info            *diskInfoPtr;
  435. !     int                streamID;
  436. !     Sun_DiskLabel         *sunLabelPtr;
  437. ! {
  438. !     int             part;
  439. !     ReturnStatus         status = SUCCESS;
  440. !     int                cyls;
  441. !     int                first;
  442. !     int                last;
  443. !     Fsdm_DiskPartition        partitionMap[SUN_NUM_DISK_PARTS];
  444. !     printInfo("SUN", diskInfoPtr);
  445. !     /*
  446. !      * Verify the magic number and the checksum.
  447. !      */
  448. !     if (sunLabelPtr->magic != SUN_DISK_MAGIC) {
  449. !     printf("Bad magic number on disk <%x> not <%x>\n",
  450. !         sunLabelPtr->magic, SUN_DISK_MAGIC);
  451. !     }
  452. !     if (!CheckSunCheckSum(sunLabelPtr)) {
  453. !     printf("Check sum incorrect, 0x%x not 0x%x\n",
  454. !         SeeSunCheckSum(sunLabelPtr), sunLabelPtr->checkSum);
  455. !     }
  456. !     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  457. !     first = sunLabelPtr->map[part].cylinder;
  458. !     if (diskInfoPtr->numHeads * diskInfoPtr->numSectors <= 0) {
  459. !         printf("%c: Cylinder %6d NumSectors %6d\n",
  460. !         first, sunLabelPtr->map[part].numBlocks);
  461. !         cyls = 0;
  462. !     } else {
  463. !         cyls = sunLabelPtr->map[part].numBlocks /
  464. !             (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  465. !         last = (cyls > 0) ? (cyls + first - 1) : first;
  466. !         printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  467. !             'a' + part, first, last, cyls,
  468. !             sunLabelPtr->map[part].numBlocks);
  469.       }
  470. -     partitionMap[part].firstCylinder = first;
  471. -     partitionMap[part].numCylinders = cyls;
  472. -     }
  473. -     if (!writeLabel) {
  474. -     return(SUCCESS);
  475. -     }
  476. -     DoNewLabel(diskInfoPtr,partitionMap,SUN_NUM_DISK_PARTS, streamID);
  477. -     strcpy(sunLabelPtr->asciiLabel, diskInfoPtr->asciiLabel);
  478. -     sunLabelPtr->numHeads = diskInfoPtr->numHeads;
  479. -     sunLabelPtr->numSectors = diskInfoPtr->numSectors;
  480. -     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  481. -     sunLabelPtr->map[part].cylinder = partitionMap[part].firstCylinder;
  482. -     sunLabelPtr->map[part].numBlocks = partitionMap[part].numCylinders *
  483. -            diskInfoPtr->numHeads * diskInfoPtr->numSectors;
  484. -     }
  485. -     sunLabelPtr->magic = SUN_DISK_MAGIC;
  486. -     MakeSunCheckSum(sunLabelPtr);
  487. -     printf("Writing new sun label\n");
  488. -     status = Disk_SectorWrite(streamID, 0, 1, sunLabelPtr);
  489. -     return status;
  490. - }
  491. - short
  492. - SeeSunCheckSum(sunLabelPtr)
  493. -     Sun_DiskLabel *sunLabelPtr;
  494. - {
  495. -         short *sp, sum = 0;
  496. -         short count = DEV_BYTES_PER_SECTOR/sizeof(short) - 1;
  497. -         sp = (short *)sunLabelPtr;
  498. -         while (count--)
  499. -                 sum ^= *sp++;
  500. -         return (sum);
  501. - }
  502. - CheckSunCheckSum(sunLabelPtr)
  503. -     Sun_DiskLabel *sunLabelPtr;
  504. - {
  505. -         short *sp, sum = 0;
  506. -         short count = DEV_BYTES_PER_SECTOR/sizeof(short);
  507. -         sp = (short *)sunLabelPtr;
  508. -         while (count--)
  509. -                 sum ^= *sp++;
  510. -         return (sum ? 0 : 1);
  511. - }
  512. - MakeSunCheckSum(sunLabelPtr)
  513. -     Sun_DiskLabel *sunLabelPtr;
  514. - {
  515. -         short *sp, sum = 0;
  516. -         short count = DEV_BYTES_PER_SECTOR/sizeof(short) - 1;
  517. -         sunLabelPtr->checkSum = 0;
  518. -         sp = (short *)sunLabelPtr;
  519. -         while (count--)
  520. -                 sum ^= *sp++;
  521. -         sunLabelPtr->checkSum = sum;
  522. - }
  523. - /*
  524. -  *----------------------------------------------------------------------
  525. -  *
  526. -  * DoSpriteLabel --
  527. -  *
  528. -  *    Sets up a Sprite label.
  529. -  *
  530. -  * Results:
  531. -  *    None.
  532. -  *
  533. -  * Side effects:
  534. -  *    None.
  535. -  *
  536. -  *----------------------------------------------------------------------
  537. -  */
  538. - ReturnStatus
  539. - DoSpriteLabel(diskInfoPtr, streamID, diskHeaderPtr)
  540. -     Disk_Info        *diskInfoPtr;
  541. -     int            streamID;
  542. -     Fsdm_DiskHeader    *diskHeaderPtr;
  543. - {
  544. -     int             part;
  545. -     int             n;
  546. -     ReturnStatus         status = SUCCESS;
  547. -     int                blocks;
  548. -     int                first;
  549. -     int                last;
  550. -     int                cyls;
  551. -     printInfo("SPRITE", diskInfoPtr);
  552. -     /*
  553. -      * Verify the magic number and the checksum.
  554. -      */
  555. -     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  556. -     printf("Bad magic number on disk <%x> not <%x>\n",
  557. -         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  558. -     }
  559. -     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  560. -     printf("Check sum incorrect, 0x%x not 0x%x\n",
  561. -         SeeSpriteCheckSum(diskHeaderPtr), FSDM_DISK_MAGIC);
  562. -     }
  563. -     for (part=0 ; part < SUN_NUM_DISK_PARTS; part++) {
  564. -     first = diskHeaderPtr->map[part].firstCylinder;
  565. -     cyls = diskHeaderPtr->map[part].numCylinders;
  566. -     last = (cyls > 0) ? (cyls + first - 1) : first;
  567. -     blocks = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  568. -         diskHeaderPtr->map[part].numCylinders;
  569. -     printf("%c: First %4d Last %4d Num %4d (Blocks %7d)\n",
  570. -         'a' + part, first, last, cyls, blocks);
  571. -     }
  572. -     if (!writeLabel) {
  573. -     return(SUCCESS);
  574.       }
  575. !     DoNewLabel(diskInfoPtr,diskHeaderPtr->map,SUN_NUM_DISK_PARTS, streamID);
  576. !     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  577. !     strcpy(diskHeaderPtr->asciiLabel, diskInfoPtr->asciiLabel);
  578. !     diskHeaderPtr->numHeads = diskInfoPtr->numHeads;
  579. !     diskHeaderPtr->numSectors = diskInfoPtr->numSectors;
  580. !     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  581. !     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  582. !     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  583. !     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  584. !     MakeSpriteCheckSum(diskHeaderPtr);
  585. !     printf("Writing new sprite label\n");
  586. !     status = Disk_SectorWrite(streamID, 0, 1, diskHeaderPtr);
  587. !     {
  588. !     FILE *fopen(), *file;
  589. !     file = fopen("label.out","w");
  590. !     fwrite(diskHeaderPtr,512,1,file);
  591. !     fclose(file);
  592. !     }
  593. !     return status;
  594. ! }
  595. ! unsigned int
  596. ! SeeSpriteCheckSum(diskHeaderPtr)
  597. !     Fsdm_DiskHeader *diskHeaderPtr;
  598. ! {
  599. !         int *sp, sum = 0;
  600. !     int i;
  601.   
  602. !         sp = (int *)diskHeaderPtr;
  603. !     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  604. !         sum ^= *sp++;
  605.       }
  606. !         return (sum);
  607. ! }
  608. ! int
  609. ! CheckSpriteCheckSum(diskHeaderPtr)
  610. !     Fsdm_DiskHeader *diskHeaderPtr;
  611. ! {
  612. !         int *sp, sum = 0;
  613. !     int i;
  614. !         sp = (int *)diskHeaderPtr;
  615. !     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  616. !         sum ^= *sp++;
  617.       }
  618. !         return (sum == FSDM_DISK_MAGIC ? 1 : 0);
  619. ! }
  620. ! MakeSpriteCheckSum(diskHeaderPtr)
  621. !     Fsdm_DiskHeader *diskHeaderPtr;
  622. ! {
  623. !         int *sp, sum = 0;
  624. !     int i;
  625. !     diskHeaderPtr->checkSum = FSDM_DISK_MAGIC;
  626. !         sp = (int *)diskHeaderPtr;
  627. !     for (i = 0; i < DEV_BYTES_PER_SECTOR; i += sizeof(int)) {
  628. !         sum ^= *sp++;
  629.       }
  630. !         diskHeaderPtr->checkSum = sum;
  631. ! }
  632. ! /*
  633. !  *----------------------------------------------------------------------
  634. !  *
  635. !  * DoNewLabel --
  636. !  *
  637. !  *    Interactively gets the information for the new disk label.
  638. !  *
  639. !  * Results:
  640. !  *    None.
  641. !  *
  642. !  * Side effects:
  643. !  *    Changes diskInfoPtr.
  644. !  *
  645. !  *----------------------------------------------------------------------
  646. !  */
  647. !     DoNewLabel(diskInfoPtr, partitionMap, numPart, streamID)
  648. !     Disk_Info        *diskInfoPtr;
  649. !     Fsdm_DiskPartition    partitionMap[];
  650. !     int            numPart;
  651. !     int            streamID;
  652. ! {
  653. !     int n, numHeads, numSectors, part;
  654. !     char answer[80];
  655. !     ReturnStatus         status = SUCCESS;
  656. !     int first, cyls, last, numCyls, lastSector, totalSectors, lastCyl;
  657. !     char            buffer[DEV_BYTES_PER_SECTOR];
  658.   
  659.   editLabel:
  660. !     printf("ascii label: \"%s\", change this? (y/n) ", 
  661. !     diskInfoPtr->asciiLabel);
  662. !     if (isYes()) {
  663. !     char *tmpPtr;
  664. !     fgets(answer, 80, stdin);
  665. !     printf("New ascii label ? ");
  666. !     tmpPtr = fgets(diskInfoPtr->asciiLabel, 128,stdin);
  667. !     if (tmpPtr == NULL) {
  668. !         exit(1);
  669. !     }
  670. !     diskInfoPtr->asciiLabel[strlen(diskInfoPtr->asciiLabel)-1] = '\0';
  671. !     }
  672. !     numHeads = diskInfoPtr->numHeads;
  673. !     numSectors = diskInfoPtr->numSectors;
  674. !     printf("Sectors: summary %d, boot %d, # boot %d, domain %d, %s ",
  675. !         diskInfoPtr->summarySector, diskInfoPtr->bootSector,
  676. !         diskInfoPtr->numBootSectors, diskInfoPtr->domainSector,
  677. !         "change this? (y/n)");
  678. !     if (isYes()) {
  679. !     diskInfoPtr->summarySector = getNum("New summary sector?");
  680. !     diskInfoPtr->bootSector = getNum("New boot sector?");
  681. !     diskInfoPtr->numBootSectors = getNum("Number of boot sectors?");
  682. !     diskInfoPtr->domainSector = getNum("New domain sector?");
  683. !     }
  684. !     printf(" %d heads, change this? (y/n) ", numHeads);
  685. !     if (isYes()) {
  686. !     numHeads = getNum("New # of heads?");
  687. !     }
  688. !     printf(" %d sectors/track, change this (y/n) ", numSectors);
  689. !     if (isYes()) {
  690. !     numSectors = getNum("New # of sectors/track?");
  691. !     }
  692.       if (numHeads * numSectors != 
  693. !     diskInfoPtr->numHeads * diskInfoPtr->numSectors) {
  694.       printf(
  695.       "The size of a cylinder changed so I have to zero the partition map.\n");
  696. !     for (part=0 ; part < numPart; part++) {
  697. !         partitionMap[part].firstCylinder = 0;
  698. !         partitionMap[part].numCylinders = 0;
  699. !     }
  700. !     }
  701. !     diskInfoPtr->numHeads = numHeads;
  702. !     diskInfoPtr->numSectors = numSectors;
  703. !     for (part=0 ; part < numPart; part++) {
  704. !     first = partitionMap[part].firstCylinder;
  705. !     cyls = partitionMap[part].numCylinders;
  706. !     last = (cyls > 0) ? (cyls + first - 1) : first;
  707. !     printf("\n%c: First %4d Last %4d Num %4d, change this? (y/n) ",
  708. !         'a' + part, first, last, cyls);
  709. !     if (isYes()) {
  710. !         int firstCyl = -1;
  711. !         int numCyls = -1;
  712. !         firstCyl = getNum("First Cyl?");
  713. !         numCyls = getNum("Num Cyls ?");
  714. !         partitionMap[part].firstCylinder = firstCyl;
  715. !         partitionMap[part].numCylinders = numCyls;
  716.       }
  717.       }
  718. !     lastCyl = 0;
  719. !     printf("\nNew Map\n");
  720. !     for (part=0 ; part < numPart; part++) {
  721. !     first = partitionMap[part].firstCylinder;
  722. !     cyls = partitionMap[part].numCylinders;
  723.       last = (cyls > 0) ? (cyls + first - 1) : first;
  724. !     if (last > lastCyl) {
  725. !         lastCyl = last;
  726. !     }
  727. !     printf("%c: First %4d Last %4d Num %4d (Cylinders %7d)\n",
  728.           'a' + part, first, last, cyls,
  729. !         partitionMap[part].numCylinders);
  730.       }
  731.       lastSector = (lastCyl + 1) * numHeads * numSectors - 1;
  732.       status = Disk_SectorRead(streamID, lastSector, 1, buffer);
  733.       if (status != 0) {
  734.       printf("I couldn't read the last sector (sector %d)!!!\n", lastSector);
  735.       }
  736.       printf("\nCommit new label? (y/n) ");
  737. !     if (!isYes()) {
  738.       printf("Try again\n");
  739.       goto editLabel;
  740.       }
  741. --- 207,418 ----
  742.       if (strcasecmp(answer, "y")) {
  743.           exit(1);
  744.       }
  745.       }
  746. !     if (!writeQuick) {
  747. !     EditLabel(toStreamID, diskLabelPtr);
  748. !     } else {
  749. !     printf("\nCommit label? (y/n) ");
  750. !     if (!IsYes()) {
  751. !         exit(0);
  752.       }
  753.       }
  754. !     if (inLabel != outLabel && fromStreamID == toStreamID) {
  755. !     status = Disk_EraseLabel(fromStreamID, inLabel);
  756. !     if (status != SUCCESS) {
  757. !         printf("Unable to erase old label.\n");
  758. !     }
  759. !     }
  760. !     printf("Write this label to all valid partitions? (y/n) ");
  761. !     n = scanf("%s", answer);
  762. !     if ((n == EOF) || strcasecmp(answer, "y")) {
  763. !     printf("Writing disk label to %s.\n", toName);
  764. !     status = Disk_WriteLabel(toStreamID, diskLabelPtr, outLabel);
  765. !     return status;
  766. !     } else {
  767. !     int part, cyls, streamID, len, cantWriteToRawDisk = FALSE;
  768. !     char c, *devName;
  769.   
  770. !     len = strlen(toName);
  771. !     devName = (char *)malloc(sizeof(char) * len + 1);
  772. !         if (devName == NULL) {
  773. !         perror("allocating string");
  774. !         exit(FAILURE);
  775.       }
  776. !     c = toName[len - 1];
  777. !     if (c >= 'a' && c < 'i') {
  778. !         /*
  779. !          * the original destination name is a partition, 
  780. !          * e.g. "/dev/rsd00a", so make sure to write the label
  781. !          * to the beginning of the raw disk and then
  782. !          * write the label to all valid partitions
  783. !          */
  784. !         sprintf(devName, "%s",toName);
  785. !         devName[--len] = '\0';  
  786. !         streamID = open(devName, O_RDWR, 0);
  787. !     } else {
  788. !         /*
  789. !          * the original destination name is a raw disk,
  790. !          * e.g. "/dev/rsd00", so write the label to the raw
  791. !          * disk and then to all valid partitions
  792. !          */
  793. !         sprintf(devName, "%s",toName);
  794. !         streamID = toStreamID;
  795.       }
  796. !     printf("raw device: %s\n", devName);
  797. !     if (streamID >= 0) {
  798. !         status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  799. !         if (status != SUCCESS) {
  800. !         printf("Unable to write disk label to ");
  801. !         printf("%s...skipping\n", devName);
  802. !         cantWriteToRawDisk = TRUE;
  803. !         }
  804. !     } else {
  805. !         cantWriteToRawDisk = TRUE;
  806.       }
  807. !     devName[len + 1] = '\0';
  808. !     for (part = 0 ; part < diskLabelPtr -> numPartitions; part++) {
  809. !         cyls = diskLabelPtr->partitions[part].numCylinders;
  810. !         if (cyls <= 0) {
  811. !         continue;
  812. !         }
  813. !         devName[len] = 'a' + part;
  814. !         printf("partition: %s\n", devName);
  815. !         if (!strcmp(devName, fromName)) {
  816. !         streamID = fromStreamID;
  817. !         } else if (!strcmp(devName, toName)) {
  818. !         streamID = toStreamID;
  819. !         } else {
  820. !         streamID = open(devName, O_RDWR, 0);
  821. !         if (streamID < 0) {
  822. !             perror("Can't open device");
  823. !             exit(FAILURE);
  824. !         }
  825. !         }
  826. !         status = Disk_HasFilesystem(streamID, diskLabelPtr);
  827. !         if (status == DISK_HAS_NO_FS) {
  828. !         printf("Could not find file system on ");
  829. !         printf("%s...skipping\n", devName);
  830. !         continue;
  831. !         }
  832. !         status = Disk_WriteLabel(streamID, diskLabelPtr, outLabel);
  833. !         if (status) {
  834. !         printf("Unable to write disk label to ");
  835. !         printf("%s...skipping\n", devName);
  836. !         } else {
  837. !         /*
  838. !          * Having written to the partition, if the partition
  839. !          * starts at cylinder 0 then we have effectively
  840. !          * written to the raw disk
  841. !          */
  842. !         if (diskLabelPtr->partitions[part].firstCylinder == 0) {
  843. !             cantWriteToRawDisk = FALSE;
  844. !         }
  845. !         }
  846. !     }
  847. !     if (cantWriteToRawDisk == TRUE) {
  848. !         devName[len] = '\0';
  849. !         printf("Warning:  either couldn't open and write to");
  850. !         printf("%s or\ncouldn't write to a valid partition ", devName);
  851. !         printf("that starts at cylinder 0.\n");
  852. !     }
  853. !     }
  854. ! }
  855. ! /*
  856. !  *----------------------------------------------------------------------
  857. !  *
  858. !  * EditLabel --
  859. !  *
  860. !  *    Interactively edits the disk label.
  861. !  *
  862. !  * Results:
  863. !  *    None.
  864. !  *
  865. !  * Side effects:
  866. !  *    Changes contents of the disk label.
  867. !  *
  868. !  *----------------------------------------------------------------------
  869. !  */
  870. ! static void
  871. ! EditLabel(streamID, labelPtr)
  872. !     int            streamID;    /* Handle on raw disk */
  873. !     Disk_Label        *labelPtr;    /* The disk label */
  874. ! {
  875. !     int                 numHeads, numSectors, part;
  876. !     ReturnStatus        status = SUCCESS;
  877. !     int                 first, cyls, last, lastSector, lastCyl;
  878. !     char            buffer[DEV_BYTES_PER_SECTOR];
  879. !     char        *tmpPtr;
  880. !     int            labelLen;
  881.   
  882.   editLabel:
  883. !     printf("Size of ascii label (%d): ", labelPtr->asciiLabelLen);
  884. !     InputNumber(&labelPtr->asciiLabelLen);
  885. !     printf("ascii label (%s): ", labelPtr->asciiLabel);
  886. !     tmpPtr = fgets(buffer, labelPtr->asciiLabelLen,stdin);
  887. !     if (tmpPtr == NULL) {
  888. !     exit(1);
  889. !     }
  890. !     printf("%d\n", strlen(buffer));
  891. !     if (strlen(buffer) > 1) {
  892. !     labelLen = Min(strlen(buffer), labelPtr->asciiLabelLen);
  893. !     strncpy(labelPtr->asciiLabel, buffer, labelLen);
  894. !     labelPtr->asciiLabel[labelLen - 1] = '\0';
  895. !     }
  896. !     printf("Number of heads (%d): ", labelPtr->numHeads);
  897. !     InputNumber(&labelPtr->numHeads);
  898. !     printf("Number of sectors per track (%d): ", labelPtr->numSectors);
  899. !     InputNumber(&labelPtr->numSectors);
  900. !     printf("Number of cylinders (%d): ", labelPtr->numCylinders);
  901. !     InputNumber(&labelPtr->numCylinders);
  902. !     printf("Number of alternate cylinders (%d): ", labelPtr->numAltCylinders);
  903. !     InputNumber(&labelPtr->numAltCylinders);
  904. !     printf("Starting sector of summary info (%d): ", labelPtr->summarySector);
  905. !     InputNumber(&labelPtr->summarySector);
  906. !     printf("Starting sector of boot program (%d): ", labelPtr->bootSector);
  907. !     InputNumber(&labelPtr->bootSector);
  908. !     printf("Number of boot sectors (%d): ", labelPtr->numBootSectors);
  909. !     InputNumber(&labelPtr->numBootSectors);
  910. !     printf("Starting sector of domain header (%d): ", labelPtr->domainSector);
  911. !     InputNumber(&labelPtr->domainSector);
  912. !     numHeads = labelPtr->numHeads;
  913. !     numSectors = labelPtr->numSectors;
  914.       if (numHeads * numSectors != 
  915. !     labelPtr->numHeads * labelPtr->numSectors) {
  916.       printf(
  917.       "The size of a cylinder changed so I have to zero the partition map.\n");
  918. !     for (part=0 ; part < labelPtr->numPartitions; part++) {
  919. !         labelPtr->partitions[part].firstCylinder = 0;
  920. !         labelPtr->partitions[part].numCylinders = 0;
  921.       }
  922.       }
  923. !     for (part=0 ; part < labelPtr->numPartitions; part++) {
  924. !     first = labelPtr->partitions[part].firstCylinder;
  925. !     cyls = labelPtr->partitions[part].numCylinders;
  926.       last = (cyls > 0) ? (cyls + first - 1) : first;
  927. !     printf("\n%c: First %4d Last %4d Num %4d (%7d sectors)\n",
  928.           'a' + part, first, last, cyls,
  929. !         cyls *  labelPtr->numHeads * labelPtr->numSectors);
  930. !     printf("First (%d): ", labelPtr->partitions[part].firstCylinder);
  931. !     InputNumber(&labelPtr->partitions[part].firstCylinder);
  932. !     printf("Num (%d): ", labelPtr->partitions[part].numCylinders);
  933. !     InputNumber(&labelPtr->partitions[part].numCylinders);
  934.       }
  935. +     lastCyl = 0;
  936. +     printf("\nNew Label\n");
  937. +     Disk_PrintLabel(labelPtr);
  938.       lastSector = (lastCyl + 1) * numHeads * numSectors - 1;
  939.       status = Disk_SectorRead(streamID, lastSector, 1, buffer);
  940.       if (status != 0) {
  941.       printf("I couldn't read the last sector (sector %d)!!!\n", lastSector);
  942. +     printf("Either the disk isn't as big as you think it is,\n");
  943. +     printf("or the device is not a raw device.\n");
  944. +     printf("(cylinders=%d, numHeads=%d, numSectors=%d)\n", lastCyl+1,
  945. +         numHeads, numSectors);
  946. +     printf("Status = %x\n", status);
  947.       }
  948.       printf("\nCommit new label? (y/n) ");
  949. !     if (!IsYes()) {
  950.       printf("Try again\n");
  951.       goto editLabel;
  952.       }
  953. ***************
  954. *** 616,1034 ****
  955.   /*
  956.    *----------------------------------------------------------------------
  957.    *
  958. !  * ConvertSunToSprite --
  959. !  *
  960. !  *    Converts a Sun label to a Sprite label. Any fields that cannot
  961. !  *    be converted directly are set to their default values.
  962. !  *    diskInfoPtr is used to get the name and the sector locations. 
  963. !  *
  964. !  * Results:
  965. !  *    None.
  966. !  *
  967. !  * Side effects:
  968. !  *    None.
  969. !  *
  970. !  *----------------------------------------------------------------------
  971. !  */
  972. ! void
  973. ! ConvertSunToSprite(diskInfoPtr, sunLabelPtr, diskHeaderPtr)
  974. !     Disk_Info            *diskInfoPtr;
  975. !     Sun_DiskLabel        *sunLabelPtr;
  976. !     Fsdm_DiskHeader        *diskHeaderPtr;
  977. ! {
  978. !     int i;
  979. !     /*
  980. !      * Verify the magic number and the checksum.
  981. !      */
  982. !     if (sunLabelPtr->magic != SUN_DISK_MAGIC) {
  983. !     printf("Bad magic number on disk <%x> not <%x>\n",
  984. !         sunLabelPtr->magic, SUN_DISK_MAGIC);
  985. !     }
  986. !     if (!CheckSunCheckSum(sunLabelPtr)) {
  987. !     printf("Check sum incorrect, 0x%x not 0x%x\n",
  988. !         SeeSunCheckSum(sunLabelPtr), sunLabelPtr->checkSum);
  989. !     }
  990. !     bzero(diskHeaderPtr, sizeof(*diskHeaderPtr));
  991. !     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  992. !     diskHeaderPtr->partition = 0;
  993. !     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  994. !     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  995. !     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  996. !     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  997. !     diskHeaderPtr->numDomainSectors = diskInfoPtr->numDomainSectors;
  998. !     diskHeaderPtr->numSectors = sunLabelPtr->numSectors;
  999. !     diskHeaderPtr->numHeads = sunLabelPtr->numHeads;
  1000. !     diskHeaderPtr->numCylinders = sunLabelPtr->numCylinders;
  1001. !     diskHeaderPtr->numAltCylinders = sunLabelPtr->numAltCylinders;
  1002. !     strncpy(diskHeaderPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1003. !     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  1004. !     diskHeaderPtr->map[i].firstCylinder = sunLabelPtr->map[i].cylinder;
  1005. !     diskHeaderPtr->map[i].numCylinders = sunLabelPtr->map[i].numBlocks /
  1006. !         (diskInfoPtr->numHeads * diskInfoPtr->numSectors);
  1007. !     }
  1008. !     MakeSpriteCheckSum(diskHeaderPtr);
  1009. ! }
  1010. ! /*
  1011. !  *----------------------------------------------------------------------
  1012. !  *
  1013. !  * ConvertSpriteToSun --
  1014. !  *
  1015. !  *    Converts a Sprite label to a Sun label. Any fields that cannot
  1016. !  *    be converted directly are set to their default values.
  1017. !  *
  1018. !  * Results:
  1019. !  *    None.
  1020. !  *
  1021. !  * Side effects:
  1022. !  *    None.
  1023. !  *
  1024. !  *----------------------------------------------------------------------
  1025. !  */
  1026. ! void
  1027. ! ConvertSpriteToSun(diskInfoPtr, diskHeaderPtr, sunLabelPtr)
  1028. !     Disk_Info            *diskInfoPtr;
  1029. !     Fsdm_DiskHeader        *diskHeaderPtr;
  1030. !     Sun_DiskLabel        *sunLabelPtr;
  1031. ! {
  1032. !     int i;
  1033. !     /*
  1034. !      * Verify the magic number and the checksum.
  1035. !      */
  1036. !     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  1037. !     printf("Bad magic number on disk <%x> not <%x>\n",
  1038. !         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  1039. !     }
  1040. !     if (!CheckSpriteCheckSum(diskHeaderPtr)) {
  1041. !     printf("Check sum incorrect, 0x%x not 0x%x\n",
  1042. !         SeeSpriteCheckSum(diskHeaderPtr), diskHeaderPtr->checkSum);
  1043. !     }
  1044. !     bzero(sunLabelPtr, sizeof(*sunLabelPtr));
  1045. !     sunLabelPtr->magic = SUN_DISK_MAGIC;
  1046. !     sunLabelPtr->numSectors = diskHeaderPtr->numSectors;
  1047. !     sunLabelPtr->numHeads = diskHeaderPtr->numHeads;
  1048. !     sunLabelPtr->numCylinders = diskHeaderPtr->numCylinders;
  1049. !     sunLabelPtr->numAltCylinders = diskHeaderPtr->numAltCylinders;
  1050. !     sunLabelPtr->partitionID = 0;
  1051. !     sunLabelPtr->bhead = 0;
  1052. !     sunLabelPtr->gap1 = 65535;
  1053. !     sunLabelPtr->gap2 = 65535;
  1054. !     sunLabelPtr->interleave = 1;
  1055. !     strncpy(sunLabelPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1056. !     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < SUN_NUM_DISK_PARTS; i++) {
  1057. !     sunLabelPtr->map[i].cylinder = diskHeaderPtr->map[i].firstCylinder;
  1058. !     sunLabelPtr->map[i].numBlocks = diskHeaderPtr->map[i].numCylinders *
  1059. !         diskInfoPtr->numHeads * diskInfoPtr->numSectors;
  1060. !     }
  1061. !     MakeSunCheckSum(sunLabelPtr);
  1062. ! }
  1063. ! /*
  1064. !  *----------------------------------------------------------------------
  1065. !  *
  1066. !  * ConvertDecToSprite --
  1067. !  *
  1068. !  *    Converts a Dec label to a Sprite label. Any fields that cannot
  1069. !  *    be converted directly are set to their default values.
  1070. !  *
  1071. !  * Results:
  1072. !  *    None.
  1073. !  *
  1074. !  * Side effects:
  1075. !  *    None.
  1076. !  *
  1077. !  *----------------------------------------------------------------------
  1078. !  */
  1079. ! void
  1080. ! ConvertDecToSprite(diskInfoPtr, decLabelPtr, diskHeaderPtr)
  1081. !     Disk_Info            *diskInfoPtr;
  1082. !     Dec_DiskLabel        *decLabelPtr;
  1083. !     Fsdm_DiskHeader        *diskHeaderPtr;
  1084. ! {
  1085. !     int i;
  1086. !     int cylLength = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  1087. !         DEV_BYTES_PER_SECTOR;
  1088. !     int totalCyls = 0;
  1089. !     /*
  1090. !      * Verify the magic number and the checksum.
  1091. !      */
  1092. !     if (decLabelPtr->magic != DEC_LABEL_MAGIC) {
  1093. !     printf("Bad magic number on disk <%x> not <%x>\n",
  1094. !         decLabelPtr->magic, DEC_LABEL_MAGIC);
  1095. !     } else if (decLabelPtr->spriteMagic != FSDM_DISK_MAGIC) {
  1096. !     printf("Disk has original dec label, not Sprite/dec label\n");
  1097. !     }
  1098. !     bzero(diskHeaderPtr, sizeof(*diskHeaderPtr));
  1099. !     diskHeaderPtr->magic = FSDM_DISK_MAGIC;
  1100. !     diskHeaderPtr->partition = 0;
  1101. !     diskHeaderPtr->bootSector = diskInfoPtr->bootSector;
  1102. !     diskHeaderPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1103. !     diskHeaderPtr->summarySector = diskInfoPtr->summarySector;
  1104. !     diskHeaderPtr->domainSector = diskInfoPtr->domainSector;
  1105. !     diskHeaderPtr->numDomainSectors = diskInfoPtr->numDomainSectors;
  1106. !     diskHeaderPtr->numSectors = decLabelPtr->numSectors;
  1107. !     diskHeaderPtr->numHeads = decLabelPtr->numHeads;
  1108. !     diskHeaderPtr->numAltCylinders = decLabelPtr->numAltCylinders;
  1109. !     *diskHeaderPtr->asciiLabel = '\0';
  1110. !     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < DEC_NUM_DISK_PARTS; i++) {
  1111. !     if (decLabelPtr->map[i].offsetBytes % cylLength != 0) {
  1112. !         printf("Warning: offset %x is not multiple of cylinder size\n",
  1113. !             decLabelPtr->map[i].offsetBytes);
  1114. !     }
  1115. !     diskHeaderPtr->map[i].firstCylinder = decLabelPtr->map[i].numBytes/
  1116. !         cylLength;
  1117. !     if (decLabelPtr->map[i].numBytes % cylLength != 0) {
  1118. !         printf("Warning: partition %x is not multiple of cylinder size\n",
  1119. !             decLabelPtr->map[i].offsetBytes);
  1120. !     }
  1121. !     diskHeaderPtr->map[i].numCylinders = decLabelPtr->map[i].numBytes /
  1122. !         cylLength;
  1123. !     totalCyls += diskHeaderPtr->map[i].numCylinders;
  1124. !     }
  1125. !     diskHeaderPtr->numCylinders = totalCyls;
  1126. !     MakeSpriteCheckSum(diskHeaderPtr);
  1127. ! }
  1128. ! /*
  1129. !  *----------------------------------------------------------------------
  1130. !  *
  1131. !  * ConvertSpriteToDec --
  1132.    *
  1133. !  *    Converts a Sprite label to a Dec label. Any fields that cannot
  1134. !  *    be converted directly are set to their default values.
  1135.    *
  1136.    * Results:
  1137.    *    None.
  1138.    *
  1139.    * Side effects:
  1140. !  *    None.
  1141.    *
  1142.    *----------------------------------------------------------------------
  1143.    */
  1144. ! void
  1145. ! ConvertSpriteToDec(diskInfoPtr, diskHeaderPtr, decLabelPtr)
  1146. !     Disk_Info            *diskInfoPtr;
  1147. !     Fsdm_DiskHeader        *diskHeaderPtr;
  1148. !     Dec_DiskLabel        *decLabelPtr;
  1149.   {
  1150. !     int i;
  1151. !     int cylLength = diskInfoPtr->numHeads * diskInfoPtr->numSectors *
  1152. !         DEV_BYTES_PER_SECTOR;
  1153. !     /*
  1154. !      * Verify the magic number and the checksum.
  1155. !      */
  1156. !     if (diskHeaderPtr->magic != FSDM_DISK_MAGIC) {
  1157. !     printf("Bad magic number on disk <%x> not <%x>\n",
  1158. !         diskHeaderPtr->magic, FSDM_DISK_MAGIC);
  1159. !     }
  1160. !     bzero(decLabelPtr, sizeof(*decLabelPtr));
  1161. !     decLabelPtr->magic = DEC_LABEL_MAGIC;
  1162. !     decLabelPtr->isPartitioned = 1;
  1163. !     decLabelPtr->numHeads = diskHeaderPtr->numHeads;
  1164. !     decLabelPtr->numSectors = diskHeaderPtr->numSectors;
  1165. !     decLabelPtr->domainSector = diskHeaderPtr->domainSector;
  1166. !     decLabelPtr->numDomainSectors = diskHeaderPtr->numDomainSectors;
  1167. !     decLabelPtr->numCylinders = diskHeaderPtr->numCylinders;
  1168. !     decLabelPtr->numAltCylinders = diskHeaderPtr->numAltCylinders;
  1169. !     decLabelPtr->bootSector = DEC_BOOT_SECTOR;
  1170. !     decLabelPtr->numBootSectors = diskHeaderPtr->numBootSectors;
  1171. !     decLabelPtr->summarySector = diskHeaderPtr->summarySector;
  1172. !     decLabelPtr->domainSector = diskHeaderPtr->domainSector;
  1173. !     decLabelPtr->numDomainSectors = diskHeaderPtr->numDomainSectors;
  1174. !     decLabelPtr->spriteMagic = FSDM_DISK_MAGIC;
  1175. !     strncpy(decLabelPtr->asciiLabel, diskInfoPtr->asciiLabel, 128);
  1176. !     for (i = 0; i < FSDM_NUM_DISK_PARTS && i < DEC_NUM_DISK_PARTS; i++) {
  1177. !     decLabelPtr->map[i].numBytes = diskHeaderPtr->map[i].numCylinders *
  1178. !             cylLength;
  1179. !     decLabelPtr->map[i].offsetBytes = diskHeaderPtr->map[i].firstCylinder *
  1180. !         cylLength;
  1181. !     }
  1182. ! }
  1183. ! /*
  1184. !  *----------------------------------------------------------------------
  1185. !  *
  1186. !  * DoDecLabel --
  1187. !  *
  1188. !  *    Sets up a Dec label.
  1189. !  *
  1190. !  * Results:
  1191. !  *    None.
  1192. !  *
  1193. !  * Side effects:
  1194. !  *    None.
  1195. !  *
  1196. !  *----------------------------------------------------------------------
  1197. !  */
  1198.   
  1199. ! ReturnStatus
  1200. ! DoDecLabel(diskInfoPtr, streamID, decLabelPtr)
  1201. !     Disk_Info            *diskInfoPtr;
  1202. !     int                streamID;
  1203. !     Dec_DiskLabel         *decLabelPtr;
  1204. ! {
  1205. !     int             part;
  1206. !     ReturnStatus         status = SUCCESS;
  1207. !     int                cyls;
  1208. !     int                first;
  1209. !     int                last;
  1210. !     int                cylLength;
  1211. !     Fsdm_DiskPartition        partitionMap[DEC_NUM_DISK_PARTS];
  1212. !     printInfo("DEC", diskInfoPtr);
  1213. !     /*
  1214. !      * Verify the magic number and the checksum.
  1215. !      */
  1216. !     if (decLabelPtr->magic != DEC_LABEL_MAGIC) {
  1217. !     printf("Bad magic number on disk <%x> not <%x>\n",
  1218. !         decLabelPtr->magic, DEC_LABEL_MAGIC);
  1219. !     }
  1220. !     cylLength = decLabelPtr->numHeads * decLabelPtr->numSectors *
  1221. !         DEV_BYTES_PER_SECTOR;
  1222. !     for (part=0 ; part < DEC_NUM_DISK_PARTS; part++) {
  1223. !     first = decLabelPtr->map[part].offsetBytes / cylLength;;
  1224. !     cyls = decLabelPtr->map[part].numBytes / cylLength;
  1225. !     last = (cyls > 0) ? (cyls + first - 1) : first;
  1226. !     printf("%c: First %4d Last %4d Num %4d (Bytes %7d)\n",
  1227. !         'a' + part, first, last, cyls,
  1228. !         decLabelPtr->map[part].numBytes);
  1229. !     partitionMap[part].firstCylinder = first;
  1230. !     partitionMap[part].numCylinders = cyls;
  1231. !     }
  1232. !     if (!writeLabel) {
  1233. !     return(SUCCESS);
  1234. !     }
  1235. !     DoNewLabel(diskInfoPtr,partitionMap,DEC_NUM_DISK_PARTS, streamID);
  1236. !     decLabelPtr->numHeads = diskInfoPtr->numHeads;
  1237. !     decLabelPtr->numSectors = diskInfoPtr->numSectors;
  1238. !     decLabelPtr->summarySector = diskInfoPtr->summarySector;
  1239. !     decLabelPtr->bootSector = diskInfoPtr->bootSector;
  1240. !     decLabelPtr->numBootSectors = diskInfoPtr->numBootSectors;
  1241. !     decLabelPtr->domainSector = diskInfoPtr->domainSector;
  1242. !     decLabelPtr->version = DEC_LABEL_VERSION;
  1243. !     decLabelPtr->magic = DEC_LABEL_MAGIC;
  1244. !     decLabelPtr->spriteMagic = FSDM_DISK_MAGIC;
  1245. !     strcpy(decLabelPtr->asciiLabel, diskInfoPtr->asciiLabel);
  1246. !     cylLength = decLabelPtr->numHeads * decLabelPtr->numSectors *
  1247. !         DEV_BYTES_PER_SECTOR;
  1248. !     for (part=0 ; part < DEC_NUM_DISK_PARTS; part++) {
  1249. !     decLabelPtr->map[part].offsetBytes = partitionMap[part].firstCylinder *
  1250. !         cylLength;
  1251. !     decLabelPtr->map[part].numBytes = partitionMap[part].numCylinders *
  1252. !         cylLength;
  1253.       }
  1254. !     printf("Writing new dec label\n");
  1255. !     status = Disk_SectorWrite(streamID, DEC_LABEL_SECTOR, 1, decLabelPtr);
  1256. !     return status;
  1257. ! }
  1258. ! /*
  1259. !  *----------------------------------------------------------------------
  1260. !  *
  1261. !  * EraseOldLabel --
  1262. !  *
  1263. !  *    Zero out the block containing the old label.
  1264. !  *
  1265. !  * Results:
  1266. !  *    Status.
  1267. !  *
  1268. !  * Side effects:
  1269. !  *    None.
  1270. !  *
  1271. !  *----------------------------------------------------------------------
  1272. !  */
  1273. ! ReturnStatus
  1274. ! EraseOldLabel(streamID, sector)
  1275. ! int streamID;
  1276. ! int sector;
  1277. ! {
  1278. !     char buffer[DEV_BYTES_PER_SECTOR];
  1279. !     bzero(buffer, DEV_BYTES_PER_SECTOR);
  1280. !     printf("Erasing label at sector %d\n",sector);
  1281. !     return Disk_SectorWrite(streamID, sector, 1, buffer);
  1282. ! }
  1283. ! /*
  1284. !  *----------------------------------------------------------------------
  1285. !  *
  1286. !  * printInfo --
  1287. !  *
  1288. !  *    Print out info in the diskInfoPtr;
  1289. !  *
  1290. !  * Results:
  1291. !  *    None.
  1292. !  *
  1293. !  * Side effects:
  1294. !  *    None.
  1295. !  *
  1296. !  *----------------------------------------------------------------------
  1297. !  */
  1298. ! printInfo(type, diskInfoPtr)
  1299. ! char                *type;
  1300. ! Disk_Info            *diskInfoPtr;
  1301. ! {
  1302. !     printf("%s LABEL <%s>\n", type, diskInfoPtr->asciiLabel);
  1303. !     printf(" %d heads %d sectors/track\n",
  1304. !     diskInfoPtr->numHeads, diskInfoPtr->numSectors);
  1305. !     printf("Boot sector = %x\n", diskInfoPtr->bootSector);
  1306. !     printf("Number of boot sectors = %x\n", diskInfoPtr->numBootSectors);
  1307. !     printf("Summary sector = %x\n", diskInfoPtr->summarySector);
  1308. !     printf("Domain sector = %x\n", diskInfoPtr->domainSector);
  1309. !     printf("Number of domain sectors = %x\n", diskInfoPtr->numDomainSectors);
  1310. ! }
  1311. ! /*
  1312. !  *----------------------------------------------------------------------
  1313. !  *
  1314. !  * getNum --
  1315. !  *
  1316. !  *    Get a number interactively.
  1317. !  *
  1318. !  * Results:
  1319. !  *    Number.
  1320. !  *
  1321. !  * Side effects:
  1322. !  *    None.
  1323. !  *
  1324. !  *----------------------------------------------------------------------
  1325. !  */
  1326. ! int
  1327. ! getNum(string)
  1328. ! char    *string;
  1329. ! {
  1330. !     int n, val;
  1331. !     char answer[80];
  1332. !     do {
  1333. !     printf("%s ",string);
  1334. !     n = scanf("%d", &val);
  1335. !     if (n == EOF) {
  1336. !         exit(1);
  1337. !     }
  1338. !     if (n == 0) {
  1339. !         /*
  1340. !          * Skip the trashy line
  1341. !          */
  1342. !         fgets(answer, sizeof(answer), stdin);
  1343. !     }
  1344. !     } while (n<1);
  1345. !     return val;
  1346. ! }
  1347.   /*
  1348.    *----------------------------------------------------------------------
  1349.    *
  1350. !  * isYes --
  1351.    *
  1352.    *    Returns TRUE if user answers y.
  1353.    *
  1354. --- 421,459 ----
  1355.   /*
  1356.    *----------------------------------------------------------------------
  1357.    *
  1358. !  * InputNumber --
  1359.    *
  1360. !  *    Get a number interactively.
  1361.    *
  1362.    * Results:
  1363.    *    None.
  1364.    *
  1365.    * Side effects:
  1366. !  *    Stuff is read from stdin..
  1367.    *
  1368.    *----------------------------------------------------------------------
  1369.    */
  1370. ! static void
  1371. ! InputNumber(number)
  1372. !     int        *number;    /* Place to store number. */
  1373.   {
  1374. !     int n, val;
  1375. !     char buffer[80];
  1376.   
  1377. !     if (fgets(buffer, 80, stdin) == NULL) {
  1378. !     exit(1);
  1379.       }
  1380. !     n = sscanf(buffer, "%d", &val);
  1381. !     if (n < 1) {
  1382. !     return;
  1383. !     }
  1384. !     *number = val;
  1385. ! }
  1386.   /*
  1387.    *----------------------------------------------------------------------
  1388.    *
  1389. !  * IsYes --
  1390.    *
  1391.    *    Returns TRUE if user answers y.
  1392.    *
  1393. ***************
  1394. *** 1040,1049 ****
  1395.    *
  1396.    *----------------------------------------------------------------------
  1397.    */
  1398. ! int
  1399. ! isYes()
  1400.   {
  1401. !     int n, val;
  1402.       char answer[80];
  1403.       n = scanf("%s", answer);
  1404.       if (n == EOF) {
  1405. --- 465,474 ----
  1406.    *
  1407.    *----------------------------------------------------------------------
  1408.    */
  1409. ! static int
  1410. ! IsYes()
  1411.   {
  1412. !     int n;
  1413.       char answer[80];
  1414.       n = scanf("%s", answer);
  1415.       if (n == EOF) {
  1416.